<?php


namespace app\common\models;


use think\model;

class Unit extends Model
{
    //  连接数据库
    protected $connection = 'exam2';
    //  连接表名
    protected $name = 'unit';
    //  自动写入时间戳字段
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    // 分页查询,获取列表
    public function fetchListByWhere($where, $order = ['id' => 'desc'], $field = '*', $page = 1, $pageSize = 10)
    {
        return $this->field($field)->where($where)->order($order)->page($page, $pageSize)->select()->toArray();
    }


    //关联班级表
    public function room()
    {
        return $this->hasOne(Room::class, 'id', 'room_id')->field('id,title');
    }

    //关联学习中心-分类表
    public function datumcate()
    {
        return $this->hasOne(DatumCate::class, 'id', 'datum_cate_id')->field('id,title');
    }
}